package com.kidback.bbloc259.app;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;

import com.amap.api.maps.MapsInitializer;
import com.amap.api.maps.offlinemap.OfflineMapManager;
import com.amap.api.services.core.ServiceSettings;
import com.kidback.bbloc259.network.base.SignKeyProvider;
import com.kidback.bbloc259.network.utils.Md5Utils;
import com.kidback.bbloc259.network.utils.SignUtils;
import com.kidback.bbloc259.util.ProcessUtils;
import com.tencent.mmkv.MMKV;


/**
 * Created by meikai on 2020/06/02.
 */
public class KidApplicationHelper {

    public static void initApplication(KidApplication application) {

        if (ProcessUtils.isMainProcess()) {
            initOnMainProcess(application);
        }

    }

    private static void initOnMainProcess(KidApplication application) {
        //Java
        MapsInitializer.updatePrivacyShow(application,true,true);
        MapsInitializer.updatePrivacyAgree(application,true);

        MapsInitializer.updatePrivacyShow(application,true,true);
        MapsInitializer.updatePrivacyAgree(application,true);

        ServiceSettings.updatePrivacyShow(application,true,true);
        ServiceSettings.updatePrivacyAgree(application,true);

        try {
            OfflineMapManager mOfflineMapManager = new OfflineMapManager(application, new OfflineMapManager.OfflineMapDownloadListener() {
                @Override
                public void onDownload(int i, int i1, String s) {

                }

                @Override
                public void onCheckUpdate(boolean b, String s) {

                }

                @Override
                public void onRemove(boolean b, String s, String s1) {

                }
            });
        }catch (Exception e){

        }


        SignUtils.register(new SignKeyProvider() {

            @Override
            public String getSignKey() {

                PackageInfo packageInfo = null;
                try {
                    packageInfo = application.getPackageManager().getPackageInfo(
                            application.getPackageName(), PackageManager.GET_SIGNATURES);
                } catch (PackageManager.NameNotFoundException e) {
                    e.printStackTrace();
                }
                Signature[] signs = packageInfo.signatures;
                Signature sign = signs[0];
                String appSignKey = sign.toCharsString();

                //SignUtils.appSignKey = ;

                return Md5Utils.md5(appSignKey);
            }
        });


    }


}
